package com.auto.admin.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.auto.admin.conf.MockConf;
import com.auto.admin.service.AbstractMockService;
import com.auto.admin.service.BaseMockService;
import com.auto.admin.util.RestTemplateUtil;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * @author liangshf
 * @Description: 基础调用服务
 * @date 2019-06-20
 */
@Service
public class BaseMockServiceImpl  extends AbstractMockService implements BaseMockService {
	private static Logger logger = LoggerFactory
			.getLogger(BaseMockServiceImpl.class);

	/**
	 * 获取自动化测试分公司列表
	 * @param param
	 * @return
	 * @throws IOException
	 */
	public JSONArray orgList(String param) {

		String urlStr = MockConf.org_list;
		String result = RestTemplateUtil.post(urlStr ,param, String.class);
		JSONObject parseObject = JSONObject.parseObject(result);
		JSONArray data = parseObject.getJSONArray("data");
		return data;
	}

	public String getPassCodeNew(String url) throws IOException {
		String result = RestTemplateUtil.get(url ,null, String.class);
		JSONObject parseObject = JSONObject.parseObject(result);
		JSONObject data = parseObject.getJSONObject("data");
		return data.getString("verifyId");
	}

	// 退出登录
	public static String loginOut() throws IOException {
		return "1";
	}

	public String loginAysnSuggest(String url, String user_name, String password,
									String verifyId, String randCode) throws IOException {
		String param = "{\"loginName\":\""+user_name+"\",\"password\":\""+password+"\",\"verifyCode\":\""
				+ randCode
				+ "\",\"loginType\":1,\"clientType\":1,\"verifyId\":\""
				+ verifyId + "\"}";
		String result = RestTemplateUtil.post(url ,param, String.class);
		String token = "";
		try {
			JSONObject parseObject = JSONObject.parseObject(result);
			JSONObject data = parseObject.getJSONObject("data");
			if(data != null){
				token = data.getString("token");
			}else {
				token = "11111";
			}
		} catch (Exception e) {
			logger.info("登录结果" + result);
			e.printStackTrace();
		}
		logger.info("登录结果" + token);
		return token;
	}
}
